/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * @author wangyaoxi
 * Date: 2010-7-16 上午10:43:29
 */
package com.ccxe.manage.service.impl;

import com.ccxe.manage.service.transaction.TransactionCcxDb;

/**
 * 事务 service
 * 
 * @author wangyx
 * 
 */
public abstract class TransactionService {

	protected TransactionCcxDb tranDb;

	protected abstract void doTransactionOperate();

	public void processTransaction() {
		try {
			tranDb = new TransactionCcxDb();
			tranDb.beginTransaction();
			doTransactionOperate();
			tranDb.commit();
		} catch (Exception e) {
			try { 
				tranDb.rollback();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			System.out.println("事务失败,回滚");
			e.printStackTrace();
		} finally {
			try {
				tranDb.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
